/**
*      author: Y_Yao
*      created: 2024-11-27 12:07:11
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 7;
int lose[N],win[N],use[N];
int n,x;

void solve()
{
    cin >> n >> x;
    vector<vector<int>> dp(n + 1,vector<int>(x + 1));
    for(int i = 1;i <= n;i++)
    {
        cin >> lose[i] >> win[i] >> use[i];
    }

    for(int i = 1;i <= n;i++)
    {
        for(int j = 0;j <= x;j++)
        {
            dp[i][j] = dp[i - 1][j] + lose[i];
            if(j >= use[i])
            {
                dp[i][j] = max(dp[i - 1][j - use[i]] + win[i],dp[i][j]);
            }
        }
    }

    cout << dp[n][x] * 5 << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}